/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_AUDIO_IMPL__
#define __CC_PYTHON_IMPORT_O_AUDIO_IMPL__

#include "python_object_audio.h"

NS_CCPY_BEGIN
	
	PYCLASS_INIT_F(CPySimpleAudioEngine, "sharedSimpleAudioEngine", "Python sharedSimpleAudioEngine Object");

	PYCLASS_BEGIN_METHOD_DEF(CPySimpleAudioEngine)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, preloadBackgroundMusic		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, playBackgroundMusic			, METH_KEYWORDS|METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, stopBackgroundMusic			, METH_KEYWORDS|METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, pauseBackgroundMusic		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, resumeBackgroundMusic		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, rewindBackgroundMusic		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, willPlayBackgroundMusic		, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, isBackgroundMusicPlaying	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, getBackgroundMusicVolume	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, setBackgroundMusicVolume	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, getEffectsVolume			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, setEffectsVolume			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, playEffect					, METH_KEYWORDS|METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, pauseEffect					, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, pauseAllEffects				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, resumeEffect				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, resumeAllEffects			, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, stopEffect					, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, stopAllEffects				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, preloadEffect				, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPySimpleAudioEngine, unloadEffect				, METH_STATIC|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPySimpleAudioEngine)

	PYCLASS_BEGIN_GETSET_DEF(CPySimpleAudioEngine)
	PYCLASS_END_GETSET_DEF(CPySimpleAudioEngine)

	PYCLASS_IMP_INTERFACE(CPySimpleAudioEngine)

	CPySimpleAudioEngine::CPySimpleAudioEngine()
	{
	}

	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, preloadBackgroundMusic)
	{
		char *pszFilePath = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &pszFilePath) )
			Py_RETURN_NONE;
		if(!pszFilePath)
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(pszFilePath);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_KW_IMPL(CPySimpleAudioEngine, playBackgroundMusic)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		static char* kwlist[] = {"pszFilePath", "bLoop", NULL};
		char *pszFilePath = NULL;
		PyObject *bLoop = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"s|O",kwlist, &pszFilePath, &bLoop))
			Py_RETURN_NONE;
		if(!pszFilePath)
			Py_RETURN_NONE;
		bool b = bLoop == Py_True;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(pszFilePath, b);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_KW_IMPL(CPySimpleAudioEngine, stopBackgroundMusic)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		static char* kwlist[] = {"bReleaseData", NULL};
		PyObject *bReleaseData = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"|O",kwlist, &bReleaseData))
			Py_RETURN_NONE;
		bool b = bReleaseData == Py_True;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(b);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, pauseBackgroundMusic)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, resumeBackgroundMusic)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, rewindBackgroundMusic)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, willPlayBackgroundMusic)
	{
		bool r = CocosDenshion::SimpleAudioEngine::sharedEngine()->willPlayBackgroundMusic();
		Py_RETURN_BOOL(r);
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, isBackgroundMusicPlaying)
	{
		bool r = CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying();
		Py_RETURN_BOOL(r);
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, getBackgroundMusicVolume)
	{
		float r = CocosDenshion::SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume();
		return Py_BuildValue("f", r);
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, setBackgroundMusicVolume)
	{
		float volume = -1;
		if( !PyArg_ParseTuple(pyArgs, "f", &volume) )
			Py_RETURN_NONE;
		if(volume < 0)
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(volume);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, getEffectsVolume)
	{
		float r = CocosDenshion::SimpleAudioEngine::sharedEngine()->getEffectsVolume();
		return Py_BuildValue("f", r);
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, setEffectsVolume)
	{
		float volume = -1;
		if( !PyArg_ParseTuple(pyArgs, "f", &volume) )
			Py_RETURN_NONE;
		if(volume < 0)
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->setEffectsVolume(volume);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_KW_IMPL(CPySimpleAudioEngine, playEffect)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		static char* kwlist[] = {"pszFilePath", "bLoop", NULL};
		char *pszFilePath = NULL;
		PyObject *bLoop = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"s|O",kwlist, &pszFilePath, &bLoop))
			Py_RETURN_NONE;
		if(!pszFilePath)
			Py_RETURN_NONE;
		bool b = bLoop == Py_True;
		unsigned int id = CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(pszFilePath, b);
		return Py_BuildValue("I", id);
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, pauseEffect)
	{
		unsigned int id = 0;
		if( !PyArg_ParseTuple(pyArgs, "I", &id) )
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseEffect(id);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, pauseAllEffects)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseAllEffects();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, resumeEffect)
	{
		unsigned int id = 0;
		if( !PyArg_ParseTuple(pyArgs, "I", &id) )
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeEffect(id);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, resumeAllEffects)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeAllEffects();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, stopEffect)
	{
		unsigned int id = 0;
		if( !PyArg_ParseTuple(pyArgs, "I", &id) )
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->stopEffect(id);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, stopAllEffects)
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, preloadEffect)
	{
		char *pszFilePath = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &pszFilePath) )
			Py_RETURN_NONE;
		if( !pszFilePath )
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(pszFilePath);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPySimpleAudioEngine, unloadEffect)
	{
		char *pszFilePath = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &pszFilePath) )
			Py_RETURN_NONE;
		if( !pszFilePath )
			Py_RETURN_NONE;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->unloadEffect(pszFilePath);
		Py_RETURN_NONE;
	}
	
NS_CCPY_END

#endif